layui.use(['form', 'layer'], function () {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;


    form.on('submit(addOrUpdateCusDevPlan)', function (data) {
        newPlanDate = data.field.planDate;
        let date = new Date(newPlanDate);
        let format = date.format("Y-m-d H:i:s");
        data.field.planDate = format;
        var index = top.layer.msg("数据提交中,请稍后...", {icon: 16, time: false, shade: 0.8});
        var url = ctx + "/cus_dev_plan/save";
        type = "post";
        if ($("input[name='rowId']").val()) {
            url = ctx + "/cus_dev_plan/update";
            type = "put";
        }
        $.ajax({
            url: url,
            data: data.field,
            type: type,
            success: function (res) {
                if (res.code == 200) {
                    layer.msg("操作成功", {icon: 6});
                    /**
                     * 关闭加载： 句柄 index
                     */
                    top.layer.close(index);
                    layer.closeAll("iframe");
                    // 刷新父页面，重新渲染表格数据，父窗口是因为当前在小小弹窗啊~
                    parent.location.reload();
                } else {
                    layer.msg(res.msg);
                }
            }
        });

        return false;
    });


    $("#close_btn").click(function () {
        var index = parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
        parent.layer.close(index);//关闭iframe的弹窗
    });

});